package com.erik.crawler.controller;

import com.erik.crawler.common.PageInfo;
import com.erik.crawler.common.ReturnInfo;
import com.erik.crawler.service.ehcache.ProxyEhcache;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class IndexController {
    @Autowired
    private ProxyEhcache ipEhcacheService;

    /**
     * show all proxyIP
     *
     * @return
     */
    @RequestMapping("/list")
    public ReturnInfo list() {
        PageInfo pageInfo = new PageInfo();
        int count = (int) this.ipEhcacheService.count();
        if (count > 0) {
            pageInfo.setTotal(count);
            pageInfo.setMap(ipEhcacheService.batchQuery());
        }
        return ReturnInfo.ok().data(pageInfo);
    }
}
